package com.aaa.mbs.schedule;

import com.aaa.mbs.dao.CouponHistoryDao;
import com.netflix.discovery.converters.Auto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author: Bug Maker
 * @date: 2021/2/21 12:51
 * @description: 优惠卷定时任务
 */
@Component
public class CouponSchedule {
    @Autowired
    private CouponHistoryDao couponHistoryDao;
    /**
     * 逻辑为当发行数量小于等于使用数量的消费券视为过期
     * 触发时间为每天中午12点
     */
        @Async
        @Scheduled(cron = "0 0 12 * * ?")
        public void deleteCoupon(){
            List<Long> list = couponHistoryDao.findOutCoupon();
            if(list.size()>0){
                couponHistoryDao.deleteByIdList(list);
            }
        }
}
